package Jame.manager
{	
	import flash.utils.Dictionary;
	
	import Jame.app.JMainApp;
	import Jame.screen.InJScreen;

	public class JLayerManager
	{
		static private var _instance:JLayerManager = null;
		
		/**---*/
		private var ms_nParent:JMainApp = null;
		/**-保存添加进来的screen对象--*/
		private var ms_nLayers:Dictionary = null;
		/**
		 * 静态单一管理显示对象类
		 * 不能创建对象实例 需要使用initJLayerManager进行初始化后 使用instance方法得到对象的实例
		 */
		public function JLayerManager(parent:JMainApp,cls:selfClass)
		{
			if(cls == null || _instance)
			{
				throw new Error("该类不能实例化，属于静态类");
			}
			else
			{
				ms_nParent = parent;
				ms_nLayers = new Dictionary(true);
			}
		}
		
		/**
		 * 添加Screen对象
		 */
		public function addScreen(screen:InJScreen,name:String):void
		{
			if(ms_nLayers.hasOwnProperty(name))
			{
				throw new Error("添加的Screen name="+name+":关键字已经存在于显示列表中");
			}
			ms_nLayers[name] = screen;
			ms_nParent.addScreen(screen);
		}
		/**
		 * 添加Screen对象
		 */
		public function addScreenAt(screen:InJScreen,name:String,index:int):void
		{
			if(ms_nLayers.hasOwnProperty(name))
			{
				throw new Error("添加的Screen name="+name+":关键字已经存在于显示列表中");
			}
			ms_nLayers[name] = screen;
			ms_nParent.addScreenAt(screen,index);
		}
		/**
		 * 删除Screen对象
		 */
		public function removeScreen(name:String):void
		{
			if(ms_nLayers.hasOwnProperty(name))
			{
				ms_nParent.removeScreen(ms_nLayers[name]);
			}
			
		}
		/**
		 * 删除所有Screen对象
		 */
		public function removeAllScreen():void
		{
			ms_nParent.removeAllScreen();
		}
		
		/**
		 * 隐藏Screen
		 */
		public function hideScreen(name:String):void
		{
			if(ms_nLayers.hasOwnProperty(name))
			{
				ms_nLayers[name].visible = false;
			}
			throw new Error("删除Screen name="+name+":不存在");
		}
		/**
		 * 显示Screen
		 */
		public function showScreen(name:String):void
		{
			if(ms_nLayers.hasOwnProperty(name))
			{
				ms_nLayers[name].visible = true;
			}
			throw new Error("删除Screen name="+name+":不存在");
		}
		
		/**
		 * 类初始化 需要传递显示对象的父对象
		 */
		static public function initJLayerManager(parent:JMainApp):void
		{
			if(_instance == null)
			{
				_instance = new JLayerManager(parent,new selfClass);
			}
		}
		
		/**
		 * 获取JLayerManager 对象
		 */
		static public function get instance():JLayerManager
		{
			return _instance;
		}
	}
}

class selfClass
{
	
}